<template>
  <div id="app">
    <div class="app-container">
      <div class="content1">
        <div class="card" style="float: left">
          <div class="img"><img src="../../assets/imgs/排列.png" style="width: 83px; height: 83px; border-radius: 50%;"></div>
          <h1>排列数</h1>
          <p><el-button type="success" size="mini" @click="openDialog()">GO</el-button></p>
        </div>

        <div class="card" style="float: left">
          <div class="img"><img src="../../assets/imgs/组合.png" style="width: 83px; height: 83px; border-radius: 50%;"></div>
          <h1>组合数</h1>
          <p><el-button type="success" size="mini" @click="dialogFormVisible1=true">GO</el-button></p>
        </div>

        <el-dialog
          :visible.sync="dialogFormVisible"
          title="请输入数字">
          <el-form ref="dataForm" :model="arrangement" label-position="left" label-width="100px" style="width: 400px; margin-left: 50px;">
            <el-form-item prop="textarea">
             <el-input-number v-model="arrangement.num1" size="small" controls-position="right" :min="1"></el-input-number>
             <el-input-number v-model="arrangement.num2" size="small" controls-position="right" :min="1"></el-input-number>
            </el-form-item>
            <div class="encode-morse">排列结果：</div>
            <div class="encode-morse" v-if="arrangementCount != ''">{{arrangementCount}}</div>
            <el-form-item>
              <el-button type="primary" @click="getArrangement">确认</el-button>
              <el-button @click="dialogFormVisible=false">取消</el-button>
            </el-form-item>
          </el-form>
        </el-dialog>

        <el-dialog
          :visible.sync="dialogFormVisible1"
          title="请输入数字">
          <el-form ref="dataForm" :model="combination" label-position="left" label-width="100px" style="width: 400px; margin-left: 50px;">
            <el-form-item prop="textarea">
              <el-input-number v-model="combination.num1" size="small" controls-position="right" :min="1"></el-input-number>
              <el-input-number v-model="combination.num2" size="small" controls-position="right" :min="1"></el-input-number>
            </el-form-item>
            <div class="encode-morse">组合结果：</div>
            <div class="encode-morse" v-if="combinationCount != ''">{{combinationCount}}</div>
            <el-form-item>
              <el-button type="primary" @click="getCombination">确认</el-button>
              <el-button @click="dialogFormVisible1=false">取消</el-button>
            </el-form-item>
          </el-form>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import {getArrangementCount, getCombinationCount} from '@/api/number'

export default {
  name: 'number',
  data() {
    return {
      dialogFormVisible: false,
      dialogFormVisible1: false,
      arrangementCount: 0,
      combinationCount: 0,
      arrangement: {
        num1: 1,
        num2: 1
      },
      combination: {
        num1: 1,
        num2: 1
      }
    }
  },
  methods: {
    openDialog () {
      this.dialogFormVisible = true
    },
    getArrangement () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          getArrangementCount(this.arrangement.num1, this.arrangement.num2).then(response => {
            if (response.data.code === 20000) {
              this.arrangementCount = response.data.data
            } else {
              this.$message({
                message: response.data.message,
                type: 'error'
              })
            }
          })
        }
      })
    },
    getCombination () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          getCombinationCount(this.combination.num1, this.combination.num2).then(response => {
            if (response.data.code === 20000) {
              this.combinationCount = response.data.data
            } else {
              this.$message({
                message: response.data.message,
                type: 'error'
              })
            }
          })
        }
      })
    }
  }
}
</script>

<style scoped>
.encode-morse {
  margin-left: 100px;
  margin-bottom: 20px;
}
.card {
  width: 190px;
  height: 240px;
  background: #262526;
  border-radius: 16px;
  text-align: center;
  color: #f0f0f0;
  font-family: inherit;
  z-index: 1;
  margin-right: 16px;
}
.img {
  display: flex;
  margin: 60px auto 10px auto;
  width: 85px;
  height: 85px;
  border: 1px solid #f0f0f0;
  border-radius: 50%;
  font-size: 11px;
  justify-content: center;
  align-items: center;
  transition: all 0.5s;
  z-index: 99;
}
p{
  opacity: 0;
  transition: all 0.5s;
}
h1{
  padding: 10px;
  font-weight: 500;
  font-size: 18px;
  color: white;
}
.card:hover .img {
  transform: scale(1.1);
  border: 1px solid #f0f0f0;
}
.card:hover h1,
.card:hover p {
  opacity: 1;
}
</style>
